package com.sky.sky_server.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.sky.sky_pojo.entity.AddressBook;

@Mapper
public interface AddressBookMapper {

    /**
     * 添加地址簿
     * @param addressBook
     * @return
     */
    @Insert("insert into address_book (user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label, is_default) values (#{userId}, #{consignee}, #{sex}, #{phone}, #{provinceCode}, #{provinceName}, #{cityCode}, #{cityName}, #{districtCode}, #{districtName}, #{detail}, #{label}, #{isDefault})")
    int insert(AddressBook addressBook);

    /**
     * 查看地址簿
     * @param userId
     * @return
     */
    @Select("select * from address_book where user_id = #{userId}")
    List<AddressBook> listByUserId(Long userId);

    /**
     * 查看默认地址簿
     * @param userId
     * @return
     */
    @Select("select * from address_book where user_id = #{userId} and is_default = 1")
    AddressBook getDefaultAddressBook(Long userId);

    /**
     * 根据id修改地址簿
     * @param addressBook
     * @return
     */
    int updateAddressBookById(AddressBook addressBook);

    /**
     * 根据userId修改所有地址默认地址为0
     * @param userId
     * @return
     */
    @Update("update address_book set is_default = 0 where user_id = #{userId}")
    int updateIsDefaultToZero(Long userId);

    /**
     * 根据id修改地址默认地址为1
     * @param id
     * @return
     */
    @Update("update address_book set is_default = 1 where id = #{id}")
    int updateIsDefaultToOne(Long id);

    /**
     * 根据id查询地址簿
     * @param id
     * @return
     */
    @Select("select * from address_book where id = #{id}")
    AddressBook getById(Long id);

    /**
     * 根据id删除地址簿
     * @param id
     * @return
     */
    @Delete("delete from address_book where id = #{id}")
    int deleteById(Long id);

    /**
     * 根据id查询地址簿
     * @param addressBookId
     * @return
     */
    @Select("select * from address_book where id = #{addressBookId}")
    AddressBook selectById(Long addressBookId);



    
}
